﻿#include "ace.CriticalSection.h"

namespace ace
{
	
#ifdef _WIN32
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
CriticalSection::CriticalSection()
{
	::InitializeCriticalSection( &m_criticalSection );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
CriticalSection::~CriticalSection()
{
	::DeleteCriticalSection( &m_criticalSection );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
void CriticalSection::Enter() const
{
	::EnterCriticalSection( &m_criticalSection );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
void CriticalSection::Leave() const
{
	::LeaveCriticalSection( &m_criticalSection );
}
#else
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
CriticalSection::CriticalSection()
{
	pthread_mutex_init( &m_mutex, NULL );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
CriticalSection::~CriticalSection()
{
	pthread_mutex_destroy( &m_mutex );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
void CriticalSection::Enter() const
{
	pthread_mutex_lock( &m_mutex );
}

//-----------------------------------------------------------------------------------
/**
*/
//-----------------------------------------------------------------------------------
void CriticalSection::Leave() const
{
	pthread_mutex_unlock( &m_mutex );
}
#endif


} /* namespace ace */